package mr.ali.webvideo.controller;


import com.github.pagehelper.PageInfo;
import mr.ali.webvideo.Exception.R;
import mr.ali.webvideo.model.Collection;
import mr.ali.webvideo.service.ICollectionService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Mr-ali
 * @since 2025-08-16
 */
@RestController
@RequestMapping("/h5/collection")
public class CollectionController {

    @Resource
    private ICollectionService collectionService;

    /**
     * 首页面的电影部分
     */
    @GetMapping("/all")
    public R<PageInfo<Collection>> list(Integer pageNum, Integer pageSize, Integer type, String order) {
        if (pageNum == null || pageNum == 0) {
            pageNum = 1;
        } else if (pageSize == null || pageNum == 0) {
            pageSize = 6;
        } else if (type == null || type == 0) {
            type = 0;
        }
        PageInfo<Collection> videoList = collectionService.findAll(pageNum, pageSize, type, order);
        return R.ok(videoList);
    }


    /**
     * 首页面的电影部分
     */
    @GetMapping("/orderLast")
    public R<PageInfo<Collection>> listOrderLast(Integer pageNum, Integer pageSize, Integer type, String order, Boolean yesVideo) {
        if (pageNum == null || pageNum == 0) {
            pageNum = 1;
        } else if (pageSize == null || pageNum == 0) {
            pageSize = 6;
        } else if (type == null || type == 0) {
            type = 0;
        } else if (yesVideo == null) {
            yesVideo = false;
        }
        PageInfo<Collection> videoList = collectionService.findAllByOrderLast(pageNum, pageSize, type, order, yesVideo);
        return R.ok(videoList);
    }

    /**
     * 标题来模糊查询
     */
    @GetMapping("/search")
    public PageInfo<Collection> searchCollections(String name, Integer pageNum, Integer pageSize) {
        char c = name.charAt(0);
        //            中文的时候才出发搜索
//        if (isChineseCharacter(c)) {
            return collectionService.searchCollections(name, pageNum, pageSize);
//        }
//        return null;
    }

    /**
     * ID查询
     */
    @GetMapping("/id")
    public Collection videoTagsById(Integer id) {
        List<Collection> collection = collectionService.videoTagsById(id);
        return collection.get(0);
    }

    @GetMapping("/seriesId")
    public List<Collection> seriesId(Integer seriesId) {
        List<Collection> collection = collectionService.findAllSeriesId(seriesId);
        return collection;
    }
}
